package com.crazy.bookstore.controller;

import com.crazy.bookstore.common.ApiRestResponse;
import com.crazy.bookstore.entity.Evaluation;
import com.crazy.bookstore.service.EvaluationService;
import com.crazy.bookstore.vo.EvaluationVO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/evaluation")
public class EvaluationController {
    @Resource
    private EvaluationService evaluationService;

    /**
     * 短评列表
     * @param bookId
     * @return
     */
    @GetMapping("/list")
    public ApiRestResponse list(Long bookId){
        List<EvaluationVO> mapList = evaluationService.selectByBookId(bookId);

        return ApiRestResponse.seccess(mapList);
    }

    /**
     * 会员短评
     * @param memberId
     * @param bookId
     * @param score
     * @param content
     * @return
     */
    @PostMapping("/evaluate")
    public ApiRestResponse evaluate(Long memberId,Long bookId,Integer score,String content){
        Evaluation evaluate = evaluationService.evaluate(memberId, bookId, score, content);
        return ApiRestResponse.seccess(evaluate);
    }

    @PostMapping("/enjoy")
    public ApiRestResponse enjoy(Long evaluationId){
        Evaluation evaluation = evaluationService.enjoy(evaluationId);
        return ApiRestResponse.seccess(evaluation);

    }

}
